home *** CD-ROM | disk | FTP | other *** search
/ Clickx 96 / Clickx 96.iso / software / tools / tool / xbmc-10.1.exe / addons / script.module.pil / lib / PIL / ImageTransform.py < prev    next >
Encoding:
Python Source  |  2009-04-06  |  2.8 KB  |  96 lines

  1. #
  2. # The Python Imaging Library.
  3. # $Id$
  4. #
  5. # transform wrappers
  6. #
  7. # History:
  8. # 2002-04-08 fl   Created
  9. #
  10. # Copyright (c) 2002 by Secret Labs AB
  11. # Copyright (c) 2002 by Fredrik Lundh
  12. #
  13. # See the README file for information on usage and redistribution.
  14. #
  15.  
  16. import Image
  17.  
  18. class Transform(Image.ImageTransformHandler):
  19.     def __init__(self, data):
  20.         self.data = data
  21.     def getdata(self):
  22.         return self.method, self.data
  23.     def transform(self, size, image, **options):
  24.         # can be overridden
  25.         method, data = self.getdata()
  26.         return image.transform(size, method, data, **options)
  27.  
  28. ##
  29. # Define an affine image transform.
  30. # <p>
  31. # This function takes a 6-tuple (<i>a, b, c, d, e, f</i>) which
  32. # contain the first two rows from an affine transform matrix. For
  33. # each pixel (<i>x, y</i>) in the output image, the new value is
  34. # taken from a position (a <i>x</i> + b <i>y</i> + c,
  35. # d <i>x</i> + e <i>y</i> + f) in the input image, rounded to
  36. # nearest pixel.
  37. # <p>
  38. # This function can be used to scale, translate, rotate, and shear the
  39. # original image.
  40. #
  41. # @def AffineTransform(matrix)
  42. # @param matrix A 6-tuple (<i>a, b, c, d, e, f</i>) containing
  43. #    the first two rows from an affine transform matrix.
  44. # @see Image#Image.transform
  45.  
  46. class AffineTransform(Transform):
  47.     method = Image.AFFINE
  48.  
  49. ##
  50. # Define a transform to extract a subregion from an image.
  51. # <p>
  52. # Maps a rectangle (defined by two corners) from the image to a
  53. # rectangle of the given size.  The resulting image will contain
  54. # data sampled from between the corners, such that (<i>x0, y0</i>)
  55. # in the input image will end up at (0,0) in the output image,
  56. # and (<i>x1, y1</i>) at <i>size</i>.
  57. # <p>
  58. # This method can be used to crop, stretch, shrink, or mirror an
  59. # arbitrary rectangle in the current image. It is slightly slower than
  60. # <b>crop</b>, but about as fast as a corresponding <b>resize</b>
  61. # operation.
  62. #
  63. # @def ExtentTransform(bbox)
  64. # @param bbox A 4-tuple (<i>x0, y0, x1, y1</i>) which specifies
  65. #    two points in the input image's coordinate system.
  66. # @see Image#Image.transform
  67.  
  68. class ExtentTransform(Transform):
  69.     method = Image.EXTENT
  70.  
  71. ##
  72. # Define an quad image transform.
  73. # <p>
  74. # Maps a quadrilateral (a region defined by four corners) from the
  75. # image to a rectangle of the given size.
  76. #
  77. # @def QuadTransform(xy)
  78. # @param xy An 8-tuple (<i>x0, y0, x1, y1, x2, y2, y3, y3</i>) which
  79. #   contain the upper left, lower left, lower right, and upper right
  80. #   corner of the source quadrilateral.
  81. # @see Image#Image.transform
  82.  
  83. class QuadTransform(Transform):
  84.     method = Image.QUAD
  85.  
  86. ##
  87. # Define an mesh image transform.  A mesh transform consists of one
  88. # or more individual quad transforms.
  89. #
  90. # @def MeshTransform(data)
  91. # @param data A list of (bbox, quad) tuples.
  92. # @see Image#Image.transform
  93.  
  94. class MeshTransform(Transform):
  95.     method = Image.MESH
  96.